// search仓库
import { reqSearchInfo } from '@/api'
export default {
  state: {
    searchList: {}
  },
  mutations: {
    SEARCHLIST(state, searchList) {
      state.searchList = searchList
    }
  },
  actions: {
    // 第二个参数用来接收组件传来的数据 params = {}表示；默认参数为空对象
    async searchList({ commit }, params = {}) {
      const res = await reqSearchInfo(params)
      if (res.code === 200) {
        commit('SEARCHLIST', res.data)
      }
    }
  },
  // 计算属性：主要作用简化仓库中的数据
  getters: {
    // 参数为当前仓库的state
    attrsList(state) {
      // 返回值有两种情况: 1.返回state.searchList.attrsList  2.返回undefined 当没有网络或者网络较慢时，state.searchList为空对象，因此返回undefined
      // return state.searchList.attrsList
      return state.searchList.attrsList || []
    },
    goodsList(state) {
      return state.searchList.goodsList || []
    },
    trademarkList(state) {
      return state.searchList.trademarkList || []
    }
  }
}
